/*
 * @Author: xiaodong 565071984@qq.com
 * @Date: 2022-05-02 19:25:33
 * @LastEditors: 肖东 565071984@qq.com
 * @LastEditTime: 2022-05-17 16:16:15
 * @FilePath: /小票/src/api/user.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { loginRSA, tokenName } from '@/config'
import { encryptedData } from '@/utils/encrypt'
import request from '@/utils/request'

export async function login(data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/index/login',
    method: 'post',
    data,
  })
}

export function getUserInfo(accessToken) {
  return request({
    url: '/userInfo',
    method: 'post',
    data: {
      [tokenName]: accessToken,
    },
  })
}

export function setUserInfo(data) {
  return request({
    url: '/User/setUerInfo',
    method: 'post',
    data: {
      ...data,
      // [tokenName]: accessToken,
    },
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'post',
  })
}

export function register() {
  return request({
    url: '/register',
    method: 'post',
  })
}
// 设置密码
export function setUserPwd(data) {
  return request({
    url: '/User/setUserPwd',
    method: 'post',
    data: {
      ...data,
    },
  })
}
// 重置密码
export function retSetTenentPwd(data) {
  return request({
    url: '/User/retSetTenentPwd',
    method: 'post',
    data: {
      ...data,
    },
  })
}

// 禁用用户
export function setTenentDelete(data) {
  return request({
    url: '/Business/setTenentDelete',
    method: 'post',
    data,
  })
}

// 禁用用户
export function setUserDelete(data) {
  return request({
    url: '/User/setUserDelete',
    method: 'post',
    data,
  })
}
